package ch.zbw.pra.sysventory.dataaccess.dataAccessObject;

import java.io.Serializable;
import java.util.List;

import org.springframework.context.ApplicationContext;

import ch.zbw.pra.sysventory.database.jdbcTemplate.SoftwareJDBCTemplate;
import ch.zbw.pra.sysventory.model.Software;
import ch.zbw.pra.sysventory.utils.DatabaseUtils;

/**
 * Bereitet Daten für den Zugriff auf die Datenbank im DatabaseLayer auf
 * 
 * @author Ralph Koster & Roberto Lucas
 */

public class SoftwareDataAccessObject implements Serializable {

	private static final long serialVersionUID = 5769244472345983964L;
	
	private ApplicationContext context;
	private SoftwareJDBCTemplate softwareJDBCTemplate;
	
	public SoftwareDataAccessObject() {
		context = DatabaseUtils.getContext();
		softwareJDBCTemplate = (SoftwareJDBCTemplate)context.getBean("software");
	}

	public List<Software> getAllSoftwareFromDatabase() {
		List<Software> softwares = softwareJDBCTemplate.listSoftwares();
		return softwares;
	}

	public List<Software> getAllSoftwaresFromComputer(Integer computerId) {
		List<Software> softwares = softwareJDBCTemplate.listAllSoftwaresFromComputer(computerId);
		return softwares;
	}

	public void writeSoftwaresToDatabase(List<Software> softwares,Integer computerId) {
		for(Software software : softwares){
			softwareJDBCTemplate.insertSoftware(software, computerId);
		}
	}
}
